<?php

class Mcontact extends CI_Model {

    private $MALH;
    private $TENLH;
    private $EMAIL;
    private $MESSAGE;
    private $CHUDE;

    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->OnCreate();
    }

    function OnCreate() {
        $this->MALH = '';
        $this->TENLH = '';
        $this->EMAIL = '';
        $this->MESSAGE = '';
        $this->CHUDE = '';
    }

    public function set_malh($data) {
        $this->MALH = $data;
    }

    public function set_tenlh($data) {
        $this->TENLH = $data;
    }

    public function set_message($data) {
        $this->MESSAGE = $data;
    }

    public function set_chude($data) {
        $this->CHUDE = $data;
    }

    public function set_email($data) {
        $this->EMAIL = $data;
    }

    public function get_malh() {
        return $this->MALH;
    }

    public function get_tenlh() {
        return $this->TENLH;
    }

    public function get_email() {
        return $this->EMAIL;
    }

    public function get_message() {
        return $this->MESSAGE;
    }

    public function get_chude() {
        return $this->CHUDE;
    }

//////////////////////////
    public function Save() {
        $data = array("MALH" => $this->MALH, "TENLH" => $this->TENLH, "EMAIL" => $this->EMAIL, "MESSAGE" => $this->MESSAGE, "CHUDE" => $this->CHUDE);
        $this->db->insert("CONTACT", $data);
    }
    public function Insert($MALH,$TENLH,$EMAIL,$MESSAGE,$CHUDE) {
        $data = array("MALH" => $MALH, "TENLH" => $TENLH, "EMAIL" => $EMAIL, "MESSAGE" => $MESSAGE, "CHUDE" => $CHUDE);
        $this->db->insert("CONTACT", $data);
    }

    public function UpdateField($strWhere = NULL) {
        $arr = array();
        $arr["MALH"] = $this->MALH;
        $arr["TENLH"] = $this->TENLH;
        $arr["EMAIL"] = $this->EMAIL;
        $arr["MESSAGE"] = $this->MESSAGE;
        $arr["CHUDE"] = $this->CHUDE;
        if (!empty($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
        }
        $this->db->update("CONTACT", $arr);
    }

    public function Delete($strWhere = NULL) {
        if (!is_null($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
            $this->db->delete("CONTACT");
        }
        else
            $this->db->empty_table('CONTACT');
    }
    public function get_top_id() {
        $Query = $this->db->query("select * from CONTACT");
        $dem = $Query->num_rows();
        return $dem + 1;
    }
}

?>
